package com.itheima.d2_buffered_stream;

import java.io.*;

/*
    目标：观察原始流和缓冲流的性能。
 */
public class TimeTest4 {
    public static void main(String[] args) throws Exception {
        long l = System.currentTimeMillis();
        test();
         long l2 = System.currentTimeMillis();
        System.out.println(l2-l);
        long l3 = System.currentTimeMillis();
        tets1();
        long l4 = System.currentTimeMillis();
        System.out.println(l4-l3);

    }
    public static void tets1() throws Exception {
         FileReader fr = new FileReader("a.txt");
        FileWriter fw = new FileWriter("c.txt");
        int len;
        char[] bytes = new char[1024];
        while ((len=fr.read(bytes))!=-1){
            fw.write(bytes,0,len);
        }
        fr.close();
        fw.close();
    }
    public static void test() throws Exception {
           FileInputStream f = new FileInputStream("a.txt");
        FileOutputStream f2 = new FileOutputStream("e.txt");
        BufferedInputStream bf = new BufferedInputStream(f);
        BufferedOutputStream bf2 = new BufferedOutputStream(f2);
        int len;
        byte[] bytes = new byte[1024];
        while ((len=bf.read(bytes))!=-1){
            bf2.write(bytes,0,len);
        }
        bf.close();
        bf2.close();
    }
}










